//
//  ZZFArticleInfoCell.m
//  YYUDemo
//
//  Created by zsp on 2017/3/17.
//  Copyright © 2017年 zsp. All rights reserved.
//

#import "ZZFArticleInfoCell.h"
#import <Masonry.h>

#import "ZZFConfigSet.h"
#import "UIColor+ZZFExtend.h"

@interface ZZFArticleInfoCell ()
@property(nonatomic, strong)UILabel *articleTitleLabel;
@property(nonatomic, strong)UILabel *articleAuthorLabel;
@property(nonatomic, strong)UILabel *articleDateLabel;
@property(nonatomic, strong)UILabel *articleSourceLabel;
@property(nonatomic, strong)UILabel *articleReadLabel;
@property(nonatomic, strong)UIButton *articleLoveButton;
@property(nonatomic, strong)UIButton *articleShareButton;
@end

@implementation ZZFArticleInfoCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self configView];
    }
    return self;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)updateData:(id)data atIndexPath:(NSIndexPath*)indexPath {
    if (data) {
        
    }else{
        self.articleTitleLabel.text=@"英语课阿萨德";
        self.articleAuthorLabel.text=@"作者：刘三姐";
        self.articleDateLabel.text=@"2015-09-06";
        self.articleSourceLabel.text=@"阿斯顿刻录机";
        self.articleReadLabel.text=@"阅读：10250";
    }
    
}

- (void)configView {
    self.articleTitleLabel=[UILabel new];
    self.articleTitleLabel.font=[UIFont systemFontOfSize:fontSize_12];
    self.articleTitleLabel.textColor=[UIColor colorWithHexString:colorHex_title_black];
    
    self.articleAuthorLabel=[UILabel new];
    self.articleAuthorLabel.font=[UIFont systemFontOfSize:fontSize_11];
    self.articleAuthorLabel.textColor=[UIColor colorWithHexString:colorHex_subtitle_gray_1];
    
    self.articleDateLabel=[UILabel new];
    self.articleDateLabel.font=[UIFont systemFontOfSize:fontSize_11];
    self.articleDateLabel.textColor=[UIColor colorWithHexString:colorHex_subtitle_gray_2];
    
    self.articleSourceLabel=[UILabel new];
    self.articleSourceLabel.font=[UIFont systemFontOfSize:fontSize_11];
    self.articleSourceLabel.textColor=[UIColor colorWithHexString:colorHex_subtitle_gray_2];
    
    self.articleReadLabel=[UILabel new];
    self.articleReadLabel.font=[UIFont systemFontOfSize:fontSize_11];
    self.articleReadLabel.textColor=[UIColor colorWithHexString:colorHex_subtitle_gray_2];
    
    self.articleLoveButton=[UIButton buttonWithType:UIButtonTypeCustom];
    [self.articleLoveButton setImage:[UIImage imageNamed:@"love"] forState:UIControlStateNormal];
    [self.articleLoveButton setImage:[UIImage imageNamed:@"loved"] forState:UIControlStateSelected];
    
    self.articleShareButton=[UIButton buttonWithType:UIButtonTypeCustom];
    [self.articleShareButton setImage:[UIImage imageNamed:@"share"] forState:UIControlStateNormal];

    UIView *supView=self.contentView;
    [supView addSubview:self.articleTitleLabel];
    [supView addSubview:self.articleAuthorLabel];
    [supView addSubview:self.articleDateLabel];
    [supView addSubview:self.articleSourceLabel];
    [supView addSubview:self.articleReadLabel];
    [supView addSubview:self.articleLoveButton];
    [supView addSubview:self.articleShareButton];
    
    [self.articleShareButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(24);
        make.trailing.equalTo(supView).offset(-15);
        make.centerY.equalTo(self.articleTitleLabel);
    }];
    
    [self.articleLoveButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(24);
        make.trailing.equalTo(self.articleShareButton).offset(-10);
        make.centerY.equalTo(self.articleTitleLabel);
    }];
    
    [self.articleTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(supView).offset(15);
        make.top.equalTo(supView).offset(15);
        make.trailing.equalTo(self.articleLoveButton.mas_leading).offset(-5);
    }];
    
    [self.articleAuthorLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self.articleTitleLabel);
        make.top.equalTo(self.articleTitleLabel).offset(5);
        make.trailing.equalTo(supView).offset(-15);
    }];
    
    [self.articleDateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self.articleTitleLabel);
        make.top.equalTo(self.articleAuthorLabel).offset(5);
        make.width.equalTo(@[self.articleSourceLabel, self.articleReadLabel]);
        make.trailing.equalTo(self.articleSourceLabel.mas_leading).offset(-5);
    }];
    
    [self.articleSourceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.articleDateLabel);
    }];
    
    [self.articleReadLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self.articleSourceLabel.mas_trailing).offset(5);
        make.centerY.equalTo(self.articleDateLabel);
        make.trailing.equalTo(supView).offset(-15);
    }];
    
    
    [self updateData:nil atIndexPath:nil];
}

@end
